package com.yl.auth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yl.auth.mapper.JiaShuMapper;
import com.yl.auth.model.entity.JiaShu;
import com.yl.auth.service.JiaShuService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "家属端登录")
@RestController
@RequestMapping("admin/jiashu/login")
public class XiaochengxuLoginController {
    @Resource
    private JiaShuService jiaShuService;
    @Resource
    private JiaShuMapper jiaShuMapper;

    @ApiOperation("家属端登录")
    @PostMapping("/login")
    public Result Login(@RequestBody JiaShu jiaShu) {
        QueryWrapper<JiaShu> wrapper = new QueryWrapper<>();
        wrapper.eq("account", jiaShu.getAccount());
        wrapper.eq("password", jiaShu.getPassword());
        JiaShu one = jiaShuService.getOne(wrapper);
        if (one != null) {
            return Result.ok(one);
        } else {
            return Result.fail();
        }
    }

    @ApiOperation(value = "全查")
    @GetMapping("/find")
    public Result find() {
        List<JiaShu> list = jiaShuService.list();
        return Result.ok(list);
    }
//    @ApiOperation("家属端登录")
//    @GetMapping("/Login")
//    public Result Login(@RequestBody JiaShu jiaShu, HttpServletRequest request) {
//        QueryWrapper<JiaShu> wrapper = new QueryWrapper<>();
//        HttpSession session = request.getSession();
//        session.setAttribute(jiaShu.getAccount(), jiaShu.getPasswprd());
//        wrapper.eq("account", jiaShu.getAccount());
//        wrapper.eq("password", jiaShu.getPasswprd());
//        JiaShu one = jiaShuMapper.selectOne(wrapper);
//        if (one != null) {
//            return Result.ok(one);
//        } else {
//            return Result.fail();
//        }
//    }
}
